<?php
function RandNumber($e){
	 for($i=0;$i<$e;$i++){
		$rand =  $rand .  rand(0, 9);  
	 }
	 return $rand;
 }
 
	if($_GET['do']== 1){
		$pdo = new PDO('mysql:host=localhost;dbname=uwika_krs_alpha', 'root', '');
		$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		$sql = "SELECT DISTINCT nrp FROM krs";
		$stmt = $pdo->prepare($sql);
		$stmt->execute();
		$sqlinsert = "INSERT INTO security (username, password, level) values (:username, :password, '0') ";
		$count = 0;
		$countall = 0;
		while($_data = $stmt->fetch(PDO::FETCH_OBJ)){
			$sql2 = "SELECT username FROM security WHERE username= :username";
			$stmt2 = $pdo->prepare($sql2);
			$stmt2->execute(array(':username' => $_data->nrp ));
			if( $stmt2->rowCount() <= 0 ){
				if($_GET['pass']==1){
					$password = RandNumber(8);
				}else{
					$password = 'password';
				}
				echo $_data->nrp.' : '.$password;
				echo '<Br />';
				$stmtinsert = $pdo->prepare($sqlinsert);
				$stmtinsert->execute(array(':username' => $_data->nrp,':password' => $password 
				)) or die("ERROR: " . implode(":", $stmtinsert->errorInfo()));
				$count++;
			}
			$countall++;
		
		}
		echo 'data affected : '.$count.' from '.$countall;
	}
?>